package org.janon.httpproxy.client.method;

import java.util.Date;

import org.janon.httpproxy.HttpModel;

public class ConnectContinueThread extends Thread
{
	private String serverHost;
	private int serverPort;
	private String key;
	private HttpModel httpModel;
	private ConnectReadMethod crm;
	private Date date = null;
	private Object lock = new Object();
	private boolean isClose = false;
	
	public ConnectContinueThread(String serverHost, int serverPort, String key,
			HttpModel httpModel, ConnectReadMethod crm)
	{
		this.serverHost = serverHost;
		this.serverPort = serverPort;
		this.key = key;
		this.httpModel = httpModel;
		this.crm = crm;
		this.date = new Date();
	}
	public void run()
	{
		try
		{
			while(true)
			{
				Thread.sleep(5000);
				if(isClose)
				{
					break;
				}
				synchronized(this.lock)
				{
					Date d = new Date();
					if(d.getTime()-this.date.getTime()>=5000)
					{
						this.date=d;
						SendConnectData.send(serverHost, serverPort, key, httpModel, null, 0, -2, crm);
					}
				}
			}
		}
		catch (Exception e)
		{
		}
	}
	
	public void setTime(Date d)
	{
		synchronized(this.lock)
		{
			this.date = d;
		}
	}
	
	public void close()
	{
		this.isClose = true;
	}
}
